<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center courseCatalog_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub courseCatalog_fd0_0'>
					<view class='flex flex-wrap align-center courseCatalog_fd0_0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">
						<text class='fu-iconfont2  courseCatalog_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center'>
						<text class='courseCatalog_fd0_0_c1_c0'>课程目录</text>
					</view>
					<view class='flex flex-wrap align-center justify-end courseCatalog_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/sy/cachVideo/cachVideo?id=${id}`">
						<image class='courseCatalog_fd0_0_c2_c0' mode="aspectFit" :src='STATIC_URL+"520.png"'></image>
					</view>
					
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			
			<view class="loading_css" v-if="isShow">
				<u-loading size="36" color="#3090FF"></u-loading>
				<view>加载中</view>
			</view>
			
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout courseCatalog_flex_1" v-else>
				<view class='flex flex-direction flex-wrap align-stretch' v-for="(item, index) in directoryList" :key="index">
					<view class='flex flex-wrap align-center courseCatalog_fd1_0_c0'>
						<text class='courseCatalog_fd1_0_c0_c0'>{{item.name}}</text>
					</view>
					<view class='flex justify-between courseCatalog_fd1_0_c1' v-for="(v, k) in item.children" :key="k" @tap.stop="viewVideo(v.aid, v.shipin, v.is_download, v.name, v.learn)">
						<view style="width: calc(100% - 40rpx);">
							<view class='flex'>
								<image class='courseCatalog_fd1_0_c1_c0_c0_c0' mode="aspectFill"
									:src='STATIC_URL+"513.png"'></image>
								<view class='courseCatalog_fd1_0_c1_c0_c0_c1'>
									<text class='courseCatalog_fd1_0_c1_c0_c0_c1_c0'>{{v.name}}</text>
								</view>
							</view>
						</view>
						<view class='flex flex-wrap align-stretch' v-if="v.is_download == 0">
							<image class='courseCatalog_fd1_0_c1_c0_c0_c0' mode="aspectFill" :src='STATIC_URL+"516.png"'>
							</image>
						</view>
						<view class='flex flex-wrap align-stretch courseCatalog_fd1_0_c2_c1' v-if="v.is_download == 1">
							<image class='courseCatalog_fd1_0_c1_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"515.png"'>
							</image>
						</view>
					</view>
				</view>
			</view>
			
			<view class="noData" v-if="directoryList.length == 0 && !isShow">
				<image :src='STATIC_URL+"no.png"'></image>
			</view>
			<!---flex布局flex布局结束-->

		</view>
	</view>
</template>
<script>
	export default {
		components: {},
		data() {
			return {
				isShow: true,
				id: "",
				directoryList: [],
				is_network: 0,
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			let {id} = options;
			if (id !== undefined) this.id = id;
			
			let _this = this;
			uni.getNetworkType({
				success: function (res) {
					// console.log(res);
					if (res.networkType == 'none') {
						_this.is_network = 0;
					} else{
						_this.is_network = 1;
					}
				}
			});
			uni.onNetworkStatusChange(function (res) {
				if (res.networkType == 'none') {
					_this.is_network = 0;
				} else{
					_this.is_network = 1;
				}
			});
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			this.isShow = true;
			this.getCourseCatalog();
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			// 课程目录  post65743c6fb43e4
			getCourseCatalog() {
				this.$api.post(global.apiUrls.post65743c6fb43e4, {
					aid: this.id
				}).then(res => {
					// console.log(res);
					this.isShow = false;
					if (res.data.code == 1) {
						this.directoryList = res.data.data;
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			viewVideo(id, url, is_download, name, learn) {
				let _this = this;
				let videoUrl = {
					url: "",
					id: id,
					is_download: is_download,
					name: name,
					learn: learn
				};
				let saveFileList = [];
				if (uni.getStorageSync('saveFileList')) {
					saveFileList = uni.getStorageSync('saveFileList');
				}
				if (_this.is_network == 0) {
					if (saveFileList.length > 0) {
						let index = -1;
						saveFileList.forEach((v, k) => {
							if (v.id == id) {
								index = k;
							}
						})
						if (index == -1) {
							_this.$message.info('视频暂未缓存');
							return;
						} else {
							videoUrl.learn = 0;
							videoUrl.url = saveFileList[index].url;
							uni.setStorageSync('videoUrl', videoUrl);
							uni.navigateTo({
								url: '/pages/sy/seeVideo/seeVideo'
							})
						}
					} else {
						_this.$message.info('视频暂未缓存');
						return;
						
					}
				} else{
					videoUrl.url = url;
					uni.setStorageSync('videoUrl', videoUrl);
					uni.navigateTo({
						url: '/pages/sy/seeVideo/seeVideo'
					})
				}
			},
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #FFFFFF;
		background-size: 100% auto;
	}

	.courseCatalog_flex_0 {
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.courseCatalog_fd0_0_c2_c0 {
		width: 48rpx;
		height: 48rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.courseCatalog_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 700;
		color: #333333;
		line-height: 50rpx;
	}

	.courseCatalog_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
	}

	.courseCatalog_fd0_0_c0 {
		width: 120rpx;
	}

	.courseCatalog_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.courseCatalog_flex_1 {
		padding: 0rpx 30rpx 0rpx 30rpx;
	}

	.courseCatalog_fd1_0_c2_c1 {
		width: 40rpx;
		line-height: 40rpx;
	}

	.courseCatalog_fd1_0_c1_c0_c0_c1_c0 {
		font-size: 28rpx;
		color: rgba(16, 16, 16, 1);
	}

	.courseCatalog_fd1_0_c1_c0_c0_c1 {
		margin: 0rpx 0rpx 0rpx 16rpx;
		width: calc(100% - 56rpx);
	}

	.courseCatalog_fd1_0_c1_c0_c0_c0 {
		width: 40rpx;
		height: 40rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.courseCatalog_fd1_0_c1 {
		background: #F8F8FA;
		background-size: 100% auto;
		padding: 24rpx;
		border-radius: 16rpx;
		margin: 20rpx 0rpx 0rpx 0rpx;
	}

	.courseCatalog_fd1_0_c0_c0 {
		font-size: 32rpx;
		font-weight: 700;
		color: rgba(16, 16, 16, 1);
	}

	.courseCatalog_fd1_0_c0 {
		margin: 32rpx 0rpx 4rpx 0rpx;
	}
</style>